home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 7.7 KB | 244 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWASinks.cpp
- // Release Version: $ 1.0d1 $
- //
- // Creation Date: 3/28/94
- //
- // Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWASINKS_H
- #include "FWASinks.h"
- #endif
-
- #ifndef FWPRIMEM_H
- #include "FWPriMem.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #pragma segment FWStream
-
- //========================================================================================
- // CLASS FW_CSink
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CSink::FW_CSink
- //----------------------------------------------------------------------------------------
-
- FW_CSink::FW_CSink()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSink::FW_CSink
- //----------------------------------------------------------------------------------------
-
- FW_CSink::FW_CSink(const FW_CSink& sink)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSink::~FW_CSink
- //----------------------------------------------------------------------------------------
-
- FW_CSink::~FW_CSink()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSink::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CSink& FW_CSink::operator=(const FW_CSink& sink)
- {
- return (*this);
- }
-
-
-
- //========================================================================================
- // CLASS FW_CRandomAccessSink
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CRandomAccessSink::FW_CRandomAccessSink
- //----------------------------------------------------------------------------------------
-
- FW_CRandomAccessSink::FW_CRandomAccessSink() :
- FW_CSink()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRandomAccessSink::FW_CRandomAccessSink
- //----------------------------------------------------------------------------------------
-
- FW_CRandomAccessSink::FW_CRandomAccessSink(const FW_CRandomAccessSink& sink) :
- FW_CSink(sink)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRandomAccessSink::~FW_CRandomAccessSink
- //----------------------------------------------------------------------------------------
-
- FW_CRandomAccessSink::~FW_CRandomAccessSink()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRandomAccessSink::GetReadableBytes
- //----------------------------------------------------------------------------------------
-
- long FW_CRandomAccessSink::GetReadableBytes() const
- {
- return GetLength() - GetPosition();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRandomAccessSink::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CRandomAccessSink& FW_CRandomAccessSink::operator=(const FW_CRandomAccessSink& sink)
- {
- return (*this);
- }
-
-
- //========================================================================================
- // CLASS FW_CMemorySink
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::FW_CMemorySink
- //----------------------------------------------------------------------------------------
-
- FW_CMemorySink::FW_CMemorySink(void* buffer, long capacity, long initialPosition) :
- FW_CRandomAccessSink(),
- fBuffer((char*)buffer),
- fCapacity(capacity),
- fPosition(initialPosition)
- {
- FW_ASSERT(fPosition < fCapacity);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::~FW_CMemorySink
- //----------------------------------------------------------------------------------------
-
- FW_CMemorySink::~FW_CMemorySink()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::Read
- //----------------------------------------------------------------------------------------
-
- void FW_CMemorySink::Read(void* destination,
- long count)
- {
- FW_ASSERT(count >= 0);
- FW_ASSERT(fPosition + count <= fCapacity);
- FW_PrimitiveCopyMemory(fBuffer + fPosition, destination, count);
- fPosition += count;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::ReadPeek
- //----------------------------------------------------------------------------------------
-
- const void * FW_CMemorySink::ReadPeek(long & availableReadBytes)
- {
- availableReadBytes = fCapacity - fPosition;
- return fBuffer + fPosition;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::ReadPeekAdvance
- //----------------------------------------------------------------------------------------
-
- void FW_CMemorySink::ReadPeekAdvance(long bytesRead)
- {
- FW_ASSERT(bytesRead >= 0);
- FW_ASSERT(fPosition + bytesRead <= fCapacity);
- fPosition += bytesRead;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::GetWritableBytes
- //----------------------------------------------------------------------------------------
-
- long FW_CMemorySink::GetWritableBytes() const
- {
- return GetReadableBytes();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::Write
- //----------------------------------------------------------------------------------------
-
- void FW_CMemorySink::Write(const void* source,
- long count)
- {
- FW_ASSERT(count >= 0);
- FW_ASSERT(fPosition + count <= fCapacity);
- FW_PrimitiveCopyMemory(source, fBuffer + fPosition, count);
- fPosition += count;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::WritePeek
- //----------------------------------------------------------------------------------------
-
- void * FW_CMemorySink::WritePeek(long& availableWriteBytes)
- {
- availableWriteBytes = fCapacity - fPosition;
- return fBuffer + fPosition;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::WritePeekAdvance
- //----------------------------------------------------------------------------------------
-
- void FW_CMemorySink::WritePeekAdvance(long bytesWritten)
- {
- FW_ASSERT(bytesWritten >= 0);
- FW_ASSERT(fPosition + bytesWritten <= fCapacity);
- fPosition += bytesWritten;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::GetLength
- //----------------------------------------------------------------------------------------
-
- long FW_CMemorySink::GetLength() const
- {
- return fCapacity;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::GetPosition
- //----------------------------------------------------------------------------------------
-
- long FW_CMemorySink::GetPosition() const
- {
- return fPosition;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::SetPosition
- //----------------------------------------------------------------------------------------
-
- void FW_CMemorySink::SetPosition(long position)
- {
- FW_ASSERT(position >= 0);
- FW_ASSERT(position <= fCapacity);
- fPosition = position;
- }
-